from django.shortcuts import render
from . import models
from django.http import HttpResponse


# Create your views here.
def add_db_view(res):
    """为数据库添加数据行"""
    try:
        models.Book.objects.create(name='C++', price=68, pub='清华出版社',market_price=98)
        models.Book.objects.create(name='python', price=20, pub='清华出版社',market_price=25)
        models.Book.objects.create(name='python3', price=60, pub='清华出版社',market_price=65)
        models.Book.objects.create(name='django', price=70, pub='机械工业出版社',market_price=75)
        models.Book.objects.create(name='jquery', price=90, pub='机械工业出版社',market_price=85)
        models.Book.objects.create(name='linux', price=80, pub='机械工业出版社',market_price=65)
        models.Book.objects.create(name='windows', price=50, pub='机械工业出版社',market_price=35)
        models.Book.objects.create(name='html5', price=90, pub='清华出版社',market_price=105)
        
        
        models.Author.objects.create(name='王老师', age=28, email='wangweichao@tedu.cn')
        models.Author.objects.create(name='吕老师', age=28, email='lvze@tedu.cn')
        models.Author.objects.create(name='祁老师', age=28, email='qitx@tedu.cn')
        return HttpResponse("添加数据行成功!")
    except Exception as e:
        return HttpResponse("添加数据行失败.")